//
//  GKZYMajorBoyAndGirlRatioView.m
//  GKZYAid
//
//  Created by tony on 16/3/7.
//  Copyright © 2016年 GKZYAid. All rights reserved.
//

#import "GKZYMajorBoyAndGirlRatioView.h"
#import "MyDefine.h"

@implementation GKZYMajorBoyAndGirlRatioView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}

-(void)configureTheViewWithGender_info:(NSDictionary *)gender_info{

    UIImageView *boyImage = [[UIImageView alloc]initWithFrame:CGRectMake(VIEWWIDTH/10, VIEWHEIGHT/5, VIEWWIDTH/5, VIEWWIDTH/5)];
    boyImage.image = [UIImage imageNamed:@"boy"];
    boyImage.layer.cornerRadius = VIEWWIDTH/10;
    boyImage.layer.masksToBounds = YES;
    boyImage.layer.borderWidth = 0.5f;
    boyImage.layer.borderColor = [[UIColor colorWithWhite:0.1 alpha:0.5]CGColor];
    [self addSubview:boyImage];
    
    UIImageView *girlImage = [[UIImageView alloc]initWithFrame:CGRectMake(VIEWWIDTH*7/10, VIEWHEIGHT/5, VIEWWIDTH/5, VIEWWIDTH/5)];
    girlImage.image = [UIImage imageNamed:@"girl"];
    girlImage.layer.cornerRadius = VIEWWIDTH/10;
    girlImage.layer.masksToBounds = YES;
    girlImage.layer.borderColor = [[UIColor colorWithWhite:0.1 alpha:0.5]CGColor];
    girlImage.layer.borderWidth = 0.5f;
    [self addSubview:girlImage];

    UILabel *ratioLab = [[UILabel alloc]initWithFrame:CGRectMake(VIEWWIDTH *0.35, VIEWHEIGHT/3, VIEWWIDTH *0.3, 20)];
    int boyratio = ceilf([gender_info[@"male_ratio"]floatValue]*100);
    int girlratio = ceilf([gender_info[@"female_ratio"]floatValue]*100);
    
    NSString *string = [NSString stringWithFormat:@"%d : %d",boyratio,girlratio];
    ratioLab.text = string;
    ratioLab.textColor = [UIColor orangeColor];
    ratioLab.textAlignment = NSTextAlignmentCenter;
    [self addSubview:ratioLab];
    
    UILabel *ratioLineLab = [[UILabel alloc]initWithFrame:CGRectMake(VIEWWIDTH*0.35, VIEWHEIGHT/3+40, VIEWWIDTH *0.3, 5)];
    [self addSubview:ratioLineLab];
    
    UILabel *blueLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, VIEWWIDTH *0.3*boyratio/(girlratio+boyratio), 5)];
    blueLab.backgroundColor = [UIColor colorWithRed:127/256.0 green:234/256.0 blue:13/256.0 alpha:1];
    [ratioLineLab addSubview:blueLab];
    UILabel *pinkLab = [[UILabel alloc]initWithFrame:CGRectMake(VIEWWIDTH*0.3*boyratio/(girlratio+boyratio),0 , VIEWWIDTH*0.3*girlratio/(boyratio+girlratio), 5)];
    pinkLab.backgroundColor = [UIColor magentaColor];
    [ratioLineLab addSubview:pinkLab];
    
    self.layer.borderColor = [[UIColor colorWithWhite:0.1 alpha:0.1]CGColor];
    self.layer.borderWidth = 0.5f;
}


@end
